// 1. let 指令
let fn1 = () => {
  let arr = []
  for (let i = 0; i < 10; i++) {
    arr[i] = function () {
      console.log(i)
    }
  }
  console.log(arr)
  // 取出第1个函数
  let f = arr[0]
  // 调用第1个函数
  f()
}
// fn1()

// 2.for循环的子作用域
let fn2 = (a) => {
  // let a = 'a' // Identifier 'a' has already been declared a变量已经声明了
  // for循环还有一个特别之处，就是设置循环变量的那部分是一个父作用域，而循环体内部是一个单独的子作用域
  for (let i = 0; i < 3; i++) {
    let i = 'abc'
    let a = 'a'
    console.log(i, a) // 输出3次abc a
  }
  for (let i = 0; i < 3; i++) {
    for (let i = 0; i < 10; i++) {
      console.log(i)
    }
  }
}
// fn2()

// 3. TDZ暂时性死区
let fn3 = (x = y, y = 2) => {
  let a = 10
  console.log(a)
  return [x, y]
}
// console.log(fn3(2, 3))

// 4. 块级作用域
let tmp = new Date()
let fn4 = () => {
  var tmp
  console.log(tmp) // undefined
  if (true) {
    tmp = 'hello world'
  }
}
// fn4()

// 5. ES6声明变量的6种方法
import { add } from './a.js'
let fn5 = () => {
  var a = 'hello'
  function f() {
    console.log(a)
  }
  let b = 'world'
  const PI = 3.14
  class Person {
    constructor(age, name) {
      this.name = name
      this.age = age
    }
  }
  let rt = add(1, 2)
  console.log(rt)
}
// fn5()

// 6. 顶层对象window,globalThis
var a = 10
let fn6 = () => {
  // NodeJS中使用 global
  console.log(window === globalThis)
}
fn6()
